<template>
  <div class="user-search">
    <el-form inline ref="formRef" :model="searchForm">
      <el-row :gutter="20">
        <el-col :span="8"
          ><el-form-item label="名称" label-width="80px" size="large" prop="name">
            <el-input v-model="searchForm.name" placeholder="请输入要查询的部门名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="部门领导" label-width="80px" size="large" prop="realname">
            <el-input placeholder="请输入要查询的部门领导" v-model="searchForm.leader"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="创建时间"
            label-width="80px"
            style="width: 71%"
            size="large"
            prop="createAt"
          >
            <el-date-picker
              v-model="searchForm.createAt"
              type="daterange"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            /> </el-form-item
        ></el-col>
      </el-row>
    </el-form>
    <!-- 搜索和重置按钮 -->
    <div class="btns">
      <el-button plain @click="handleResetClick" icon="Refresh">重置</el-button>
      <el-button plain type="primary" icon="Search" @click="handleQueryClick">查询</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { ElForm } from 'element-plus'
// 定义自定义事件
const emit = defineEmits(['queryClick', 'resetClick'])

const searchForm = reactive({
  name: '',
  leader: '',
  createAt: ''
})
const formRef = ref<InstanceType<typeof ElForm>>()
// 重置
const handleResetClick = () => {
  formRef.value?.resetFields()
  emit('resetClick')
}
// 查询
const handleQueryClick = () => {
  emit('queryClick', searchForm)
}
</script>

<style lang="less" scoped>
.user-search {
  background-color: #fff;
  padding: 20px;
}
.btns {
  text-align: right;
  padding: 0px 50px 10px 0;
}
</style>
